import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.concurrent.TransferQueue;

/**
 * @Author 12629
 * @Date 2022/3/19 12:28
 * @Description：
 */
/*public class Solution {

    public TreeNode prev = null;

    public void ConvertChild(TreeNode pCur) {
        if(pCur == null) {
            return;
        }
        ConvertChild(pCur.left);
        // System.out.print(pCur.val+" ");
        //这里拿到了节点之后 ，开始进行修改当前节点的指向
        pCur.left = prev;
        if(prev != null) {
            prev.right = pCur;
        }
        prev = pCur;

        ConvertChild(pCur.right);
    }

    public TreeNode Convert(TreeNode pRootOfTree) {
        if(pRootOfTree == null) {
            return null;
        }
        //修改结构
        ConvertChild(pRootOfTree);

        //pRootOfTree根节点
        TreeNode head = pRootOfTree;

        while(head.left != null) {
            head = head.left;
        }
        return head;
    }
}*/


 class Main {
    public static int i = 0;
    public static TestBinaryTree.TreeNode createTree(String str) {
        TestBinaryTree.TreeNode root = null;
        if(str.charAt(i) != '#') {
            root = new TestBinaryTree.TreeNode(str.charAt(i));
            i++;
            //递归创建root.left  和  root.right
            root.left = createTree(str);
            root.right = createTree(str);
        }else{
            i++;
        }
        return root;
    }

    public static void inorder(TestBinaryTree.TreeNode root) {
        if(root == null) {
            return;
        }
        inorder(root.left);
        System.out.print(root.val+" ");
        inorder(root.right);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()) {
            String str = in.nextLine();
            TestBinaryTree.TreeNode root = createTree(str);
            inorder(root);
        }
    }
}
public class TestDemo {

    public static void main(String[] args) {
        TestBinaryTree testBinaryTree = new TestBinaryTree();
        TestBinaryTree.TreeNode root = testBinaryTree.creteTree2();

        testBinaryTree.postorderTraversal(root);

    }



    public static void main1(String[] args) {
        TestBinaryTree testBinaryTree = new TestBinaryTree();
        TestBinaryTree.TreeNode root = testBinaryTree.creteTree();
        testBinaryTree.preOrder(root);
        System.out.println();

        testBinaryTree.inOrder(root);
        System.out.println();

        testBinaryTree.postOrder(root);
        System.out.println();

        System.out.println("=========节点的个数======");

        testBinaryTree.size1(root);

        System.out.println(TestBinaryTree.count);

        System.out.println("=========节点的个数======");
        System.out.println(testBinaryTree.size2(root));

        System.out.println("叶子节点的个数：");
        testBinaryTree.getLeafNodeCount1(root);
        System.out.println(TestBinaryTree.leafCount);

        System.out.println(testBinaryTree.getLeafNodeCount2(root));

        System.out.println("=============第K层==========");
        System.out.println(testBinaryTree.getKLevelNodeCount(root, 4));

        System.out.println("============查找某个数据========");
        TestBinaryTree.TreeNode ret = testBinaryTree.find(root,'A');
        try {
            System.out.println(ret.val);
        }catch (NullPointerException e) {
            System.out.println("没有你要找的数据！");
            e.printStackTrace();
        }


        Queue<TestBinaryTree.TreeNode> queue = new LinkedList<>();
        queue.offer(null);
        queue.offer(null);
        queue.offer(null);
        queue.offer(null);

        System.out.println("size:"+queue.size());


        System.out.println("============测试是不是完全二叉树===============");
        boolean flg = testBinaryTree.isCompleteTree(root);
        System.out.println(flg);

        System.out.println("==========层序遍历============");

        testBinaryTree.leveOrder(root);

    }
}
